<%@ page import="io.github.luyanfei.Question"%>
<%@ page import="io.github.luyanfei.QuestionType"%>
<%@ page import="io.github.luyanfei.QuestionAnswer"%>

<div
	class="form-group ${hasErrors(bean: questionInstance, field: 'title', 'error')} required">
	<label for="title" class="col-md-3 control-label"> <g:message
			code="question.title.label" default="Title" /> <span
		class="required-indicator">*</span>
	</label>
	<div class="col-md-9">
		<g:textField name="title" required=""
			value="${questionInstance?.title}" class="form-control" />
	</div>
</div>

<div
	class="form-group ${hasErrors(bean: questionInstance, field: 'content', 'error')} required">
	<label for="content" class="col-md-3 control-label"> <g:message
			code="question.content.label" default="Content" /> <span
		class="required-indicator">*</span>
	</label>
	<div class="col-md-9">
		<g:textArea name="content" required=""
			value="${questionInstance?.content}" rows="5" class="form-control" />
	</div>
</div>

<div
	class="form-group ${hasErrors(bean: questionInstance, field: 'feedback', 'error')} required">
	<label for="feedback" class="col-md-3 control-label"> <g:message
			code="question.feedback.label" default="Feedback" /> <span
		class="required-indicator">*</span>
	</label>
	<div class="col-md-9">
		<g:textArea name="feedback" required=""
			value="${questionInstance?.feedback}" class="form-control" rows="3" />
	</div>
</div>

<div
	class="form-group ${hasErrors(bean: questionInstance, field: 'hidden', 'error')} ">
	<label for="hidden" class="col-md-3 control-label"> <g:message
			code="question.hidden.label" default="Hidden" />

	</label>
	<div class="col-md-9">
		<g:checkBox name="hidden" value="${questionInstance?.hidden}"
			class="form-control" />
	</div>
</div>

<div
	class="form-group ${hasErrors(bean: questionInstance, field: 'defaultMark', 'error')} required">
	<label for="defaultMark" class="col-md-3 control-label"> <g:message
			code="question.defaultMark.label" default="Default Mark" /> <span
		class="required-indicator">*</span>
	</label>
	<div class="col-md-2">
		<g:select name="defaultMark" from="${1..10}"
			value="${fieldValue(bean: questionInstance, field: 'defaultMark')}"
			required="" class="form-control" />
	</div>
	<label for="penalty" class="col-md-3 control-label"> <g:message
			code="question.penalty.label" default="Penalty" /> <span
		class="required-indicator">*</span>
	</label>
	<div class="col-md-2">
		<g:field name="penalty"
			value="${fieldValue(bean: questionInstance, field: 'penalty')}"
			required="" class="form-control" />
	</div>
</div>

<g:if test="${questionInstance?.answers}">
	<g:each in="${questionInstance.answers}" var="ans" status="index">
		<div class="form-group">
			<div class="col-md-offset-3 col-md-9">
				<h3>
					<g:message code="questionAnswer.label" args="[index]" />
				</h3>
			</div>
		</div>

		<div class="form-group required">
			<label for="answer${index}" class="col-md-3 control-label"> <g:message
					code="questionAnswer.answer.label" default="Answer" /> <span
				class="required-indicator">*</span>
			</label>
			<div class="col-md-9">
				<g:textField name="answers[${status}].answer" required="" value="${ans?.answer}" />
			</div>
		</div>

		<div class="form-group required">
			<label for="feedback${status}" class="col-md-3 form-control">
				<g:message code="questionAnswer.feedback.label" default="Feedback" />
				<span class="required-indicator">*</span>
			</label>
			<div class="col-md-9">
				<g:textField name="answers[${status}].feedback" required="" value="${ans?.feedback}" />
			</div>
		</div>

		<div class="form-group required">
			<label for="fraction${status}" class="form-control col-md-3">
				<g:message code="questionAnswer.fraction.label" default="Fraction" />
				<span class="required-indicator">*</span>
			</label>
			<div class="col-md-9">
				<g:field name="answers[${status}].fraction" required=""
					value="${fieldValue(bean: ans, field: 'fraction')}" />
			</div>
		</div>

	</g:each>
</g:if>
